package com.wang.interview.threads;

import java.util.Vector;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author: wang
 * @date: 2021/7/25 12:04
 * @description: Vector 是线程安全的，因为其底层方法是加了synchronized的
 */
public class VectorTest {
    public static void main(String[] args) {
        Vector<Integer> v = new Vector<>();
        ExecutorService pool = Executors.newCachedThreadPool();
        for (int i = 0; i < 10; i++) {
            v.add(1);
        }
        for (int i = 0; i < 10; i++) {
            System.out.println(v);   // 稳如老狗，不会报错
        }
        pool.shutdown();
    }
}
